#!/bin/bash

##############################################################
((EUID == 0)) || { echo "Try again as root!"; exit 0; }

###############################################################
#remove existing DNP printer queues
CUPS_PPDs=/etc/cups/ppd
for ppd in $(ls $CUPS_PPDs ); do 
  ppdPath=$CUPS_PPDs/$ppd
  if test "$(awk '/^[*]Product/&&/Dai Nippon Printing/' $ppdPath)";then
    echo removing queue \"${ppd%.ppd}\"
    lpadmin -x ${ppd%.ppd}
  fi
done

# remove existing DNP folder
rm -rf "/Library/Printers/DNP/"

# remove existing DNP PPDs
Library_PPDs=/Library/Printers/PPDs/Contents/Resources
for ppd in $(find $Library_PPDs -name 'DS*.ppd' -o -name 'DNP-*.ppd'); do 
  echo testing file $ppd
  ppdPath=$Library_PPDs/$ppd
  if test "$(awk '/^[*]Product/&&/Dai Nippon Printing/' $ppd)";then
    echo deleting ppd file \"${ppd}\"
    rm -f ${ppd}
  fi 
done

exit 0
